package com.haiqi.modules.ship.service;

import com.haiqi.common.persistence.dao.FleetInfoMapper;
import com.haiqi.common.persistence.entity.FleetInfo;
import com.haiqi.common.utils.UUIDGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by HaiQi on 2017-4-1.
 */
@Service
public class FleetService {
    @Autowired
    private FleetInfoMapper fleetInfoMapper;

    /**
     * 获取一条公司与船舶之间的对应关系
     * @param compang_id 公司ID
     * @param mmsi 其他公司的船舶呼号（九位码）
     * @return
     */
    public FleetInfo getOneFleetById(String compang_id,String mmsi){
        FleetInfo fleetInfo = null;
        fleetInfo = fleetInfoMapper.selectByCompnayIdAndMMSI(compang_id, mmsi);
        return fleetInfo;
    }

    /**
     * 插入一条船队信息
     * @param fleetInfo 船队信息
     * @return
     */
    public boolean insertOneFleet(FleetInfo fleetInfo){
        if(fleetInfo.getId()==null){
            fleetInfo.setId(UUIDGenerator.getUUID());
        }
        int result = fleetInfoMapper.insert(fleetInfo);
        if(result>0){
            return true;
        }else{
            return false;
        }
    }
}
